package com.dragon.mmochat.model.scheduleJob;

import org.quartz.Job;
import org.quartz.JobExecutionContext;

import com.dragon.mmochat.model.activity.MmochatDaoActivity;
import com.dragon.mmochat.model.enumType.MmochatPayLotteryState;
import com.dragon.mmochat.service.MmochatChatService;
import com.dragon.mmochat.service.MmochatFriendService;
import com.dragon.mmochat.service.MmochatPropService;

public class DaoActivityJob implements Job {
	@Override
	public void execute(JobExecutionContext context) {
		try {
			MmochatDaoActivity payAward = (MmochatDaoActivity) context
					.getJobDetail().getJobDataMap().get("data");
			if (payAward != null) {
				switch (payAward.getState()) {
				case 开始统计: {
					// 初始化设置payLotteryInfo数据
					MmochatPropService.daoActivityInfo = payAward;

					// 系统公告
					String sysInfo = MmochatPropService.daoActivityInfo
							.getStartMsg();
					if (sysInfo != null) {
						MmochatChatService.sendSystemMsg(sysInfo);
						MmochatFriendService
								.sendSystemMsgToAllByFriendMessage(sysInfo);
					}
					break;
				}
				case 停止统计: {
					MmochatPropService.daoActivityInfo
							.setState(MmochatPayLotteryState.停止统计);

					// 进行抽奖及奖励发放
					MmochatPropService.daoActivityInfo.doAward();

					// 系统公告
					String sysInfo = "本次刷道比赛已经圆满结束，大家可以按9键查看获奖名单!";
					if (sysInfo != null) {
						MmochatChatService.sendSystemMsg(sysInfo);
					}
					break;
				}
				case 活动结束: {
					MmochatPropService.daoActivityInfo
							.setState(MmochatPayLotteryState.活动结束);
					MmochatPropService.daoActivityInfo = null;
					break;
				}
				default:
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
